const db = wx.cloud.database()
Page({
  data:{
    userName:'',
    zhanghu:'',
    pwd:'',
    secondPwd:'',
    
  },
  // 获取输入的用户名
  userName:function(res){
    console.log("获取输入的用户名：",res.detail.value)
    this.setData({
      userName:res.detail.value
    })
  },
  // 获取输入的账号
  zhanghu:function(res){
    console.log("获取输入的账号：",res.detail.value)
    this.setData({
      zhanghu:res.detail.value
    })
  },
  // 获取第一次输入的密码
  pwd:function(res){
    console.log("获取输入的密码：",res.detail.value)
    this.setData({
      pwd:res.detail.value
    })
  },
  // 获取第二次输入的密码
  secondPwd:function(res){
    console.log("获取第二次输入的密码：",res.detail.value)
    this.setData({
      secondPwd:res.detail.value
    })
  },

  // 立即注册
  submit:function(res){
    let userName = this.data.userName
    let zhanghu = this.data.zhanghu
    let pwd = this.data.pwd
    let secondPwd = this.data.secondPwd
    db.collection('user').add({
      data:{
        userName:userName,
        zhanghu:zhanghu,
        pwd:pwd,
        secondPwd:secondPwd
      },
      success:function(res){
        if(userName == '' || zhanghu == '' || pwd == '' || secondPwd == ''){
          wx.showToast({
            icon:'none',
            title: '您还有信息未填',
          })
          return
        }else if(pwd !== secondPwd){
          wx.showToast({
            icon:'none',
            title: '两次密码不一致',
          })
          return
        }else{
          wx.showToast({
            title: '注册成功',
          })
          console.log("注册成功",res)
        }
        return
      },
      fail:function(err){
        wx.showToast({
          icon:'none',
          title: '注册失败',
        })
        console.log("注册失败",res)
      }
    })
  }
})